<?php
$this->widget('application.extensions.fancybox.EFancyBox', array('target' => '.product', 'config' => array('width' => 800, 'height' => 400,'type'=>'iframe','hideOnOverlayClick'=>false, 'onClosed'=>'js:function(){window.location.href="'.Yii::app()->createUrl("admin/productGroupUpdate",array("groupId"=>$model->groupId)).'";}')));
$this->widget('application.extensions.fancybox.EFancyBox', array('target' => '.multi', 'config' => array('width' => 800, 'height' => 600,'type'=>'iframe','hideOnOverlayClick'=>false, 'onClosed'=>'js:function(){window.location.href="'.Yii::app()->createUrl("admin/productGroupUpdate",array("groupId"=>$model->groupId)).'";}')));
$this->widget('application.extensions.fancybox.EFancyBox', array('target' => '.photo', 'config' => array('width' => 800, 'height' => 130,'type'=>'iframe','hideOnOverlayClick'=>false, 'onClosed'=>'js:function(){window.location.href="'.Yii::app()->createUrl("admin/productGroupUpdate",array("groupId"=>$model->groupId)).'";}')));
$this->widget('application.extensions.fancybox.EFancyBox', array('target' => '.import', 'config' => array('width' => 800, 'height' => 600,'type'=>'iframe','hideOnOverlayClick'=>false, 'onClosed'=>'js:function(){window.location.href="'.Yii::app()->createUrl("admin/productGroupUpdate",array("groupId"=>$model->groupId)).'";}')));
?>

<script>
function fillDes(feild){
	$.post('<?php echo CHtml::normalizeUrl(array('/admin/getDes'));?>',{'feild':feild,'gid':'<?=$model->groupId?>'}, function (data) {
        var ret = $.parseJSON(data);
        if (ret != null && ret.success != null && ret.success) {
			if(feild=='Description'){
				Description.html(ret.msg);
			}else{
				Listing_Des.html(ret.msg);
			}			
        }
	});	
}
</script>
<div style="width:100%; float:left; margin-bottom:10px; text-align:right;">
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'group-form',
	'htmlOptions'=>array('name'=>'jobForm'),
	'enableAjaxValidation'=>false,
)); ?>
	<?php echo $form->errorSummary($model); ?>

	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td width="15%" class="td_right"><?php echo $form->label($model,'groupName'); ?>: </td>
			<td width="35%">
				<?php echo $form->textField($model,'groupName',array('class'=>'disabled input_size4','disabled'=>'disabled')); ?>
			</td>
			<td width="15%" class="td_right"><?php echo $form->label($model,'groupNumber'); ?>: </td>
			<td>
				<?php echo $form->textField($model,'groupNumber',array('class'=>'input_size4')); ?>
			</td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'groupAmazonPrice'); ?>: </td>
			<td>
				<?php echo $form->textField($model,'groupAmazonPrice',array('class'=>'input_size4')); ?>
			</td>
			<td class="td_right"><?php echo $form->label($model,'groupEbayPrice'); ?>: </td>			
			<td>
				<?php echo $form->textField($model,'groupEbayPrice',array('class'=>'input_size4')); ?>
			</td>
		</tr>		
		<tr>
			<td class="td_right"><?php echo $form->label($model,'groupTitle'); ?>: </td>
			<td colspan="3">
				<?php echo $form->textField($model,'groupTitle',array('class'=>'input_size3'));?>
			</td>			
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'groupDes'); ?>: </td>
			<td colspan="3">
				<?php
				$this->widget('application.extensions.kindeditor4.KindEditorWidget',
						array('model' => $model,'attribute' => 'groupDes',
							'htmlOptions'=>array('width' => '100%'),
							'miniMode'=>true,'editorname'=>'Description'));
				?>
				<a onclick="fillDes('Description')" href="###">填充</a>
			</td>			
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'groupListingDes'); ?>: </td>
			<td colspan="3">
				<?php
				$this->widget('application.extensions.kindeditor4.KindEditorWidget',
						array('model' => $model,'attribute' => 'groupListingDes',
							'htmlOptions'=>array('width' => '100%'),
							'miniMode'=>true,'editorname'=>'Listing_Des'));
				?>
				<a onclick="fillDes('Listing_Des')" href="###">填充</a>
			</td>			
		</tr>
		<tr>
			<td colspan="4" style="text-align:center;"><?php echo CHtml::submitButton($model->isNewRecord ? '新建' : '更新'); ?></td>
		</tr>	
	</table>
<?php $this->endWidget(); ?>
<?php
if($model->groupId){
	if($model->groupType==1){
?>
<div style="text-align:right; padding:10px 10px 0 0; font-weight:bold;"><a id="item" class='product' href="<?=Yii::app()->createUrl('admin/addItem',array('groupId'=>$model->groupId))?>">增加产品</a></div>
<?php
	}else{
?>
<div style="text-align:right; padding:10px 10px 0 0; font-weight:bold;"><a id="item" class='multi' href="<?=Yii::app()->createUrl('admin/addMulti',array('groupId'=>$model->groupId))?>">增加产品</a></div>
<?php
	}
?>
<?php
	$products = $model->products;
	if($products){    
?>
<table class="detail-view" style="margin-top:10px;">
    <tbody>
		<tr class="head">
			<td width="15%" style="text-align:center;">产品编号</td>
			<td style="text-align:center;">产品细节</td>
			<td width="8%" style="text-align:center;">库存</td>
			<td width="8%" style="text-align:center;">在运</td>
			<td width="8%" style="text-align:center;">LA成本</td>
			<td width="8%" style="text-align:center;">数量</td>
			<td width="8%" style="text-align:center;">编辑</td>
			<td width="8%" style="text-align:center;">删除</td>
        </tr>
<?php
		$i = 0;
		$cssArr = array(0 => 'odd', 1 => 'even');
		foreach($products as $product){
			$trClass = $cssArr[$i % 2];
			$i++;
?>
        <tr class="<?= $trClass ?>">
            <td><?= $product->product->ProductModel ?></td>
			<td><?=$product->product->ProductDetail?></td>
			<td style="text-align:center;"><?= $product->product->OnHand ?></td>
			<td style="text-align:center;"><?= $product->product->OnShipping ?></td>
			<td style="text-align:center;"><?= $product->product->LACost ?></td>
			<td style="text-align:center;"><?= $product->number ?></td>
			<td style="text-align:center;"><a class="product" href="<?=Yii::app()->createUrl('admin/addItem',array('groupId'=>$model->groupId,'groupItemId'=>$product->groupItemId))?>">编辑</a></td>
			<td style="text-align:center;"><a class="fan1" href="<?=Yii::app()->createUrl('admin/deleteItem',array('id'=>$product->groupItemId))?>">删除</a></td>
        </tr>
<?php        
		}
?>
    </tbody>
</table>
<?php
	}
?>
<div style="text-align:right; padding:10px 10px 0 0; font-weight:bold;">
	<a id="import" class='import' style="margin-right:100px;" href="<?=Yii::app()->createUrl('admin/importPhoto',array('groupId'=>$model->groupId))?>">从子产品导入图片</a>
	<a id="photo" class='photo' href="<?=Yii::app()->createUrl('admin/addPhoto',array('groupId'=>$model->groupId))?>">增加图片</a>
</div>
<?php
	$photos = $model->photos;
	if($photos){    
?>
<table class="detail-view" style="margin-top:10px;">
    <tbody>
		<tr class="head">
			<td width="15%" style="text-align:center;">图片名称</td>
			<td style="text-align:center;">图片地址</td>
			<td width="22%" style="text-align:center;">更新时间</td>
			<td width="8%" style="text-align:center;">编辑</td>
			<td width="8%" style="text-align:center;">删除</td>
        </tr>
<?php
		$i = 0;
		$cssArr = array(0 => 'odd', 1 => 'even');
		foreach($photos as $photo){
			$trClass = $cssArr[$i % 2];
			$i++;
?>
        <tr class="<?= $trClass ?>">
            <td><?= $photo->title ?></td>
			<td><?=$photo->path?></td>
			<td><?=$photo->dateline?></td>
			<td style="text-align:center;"><a class="photo" href="<?=Yii::app()->createUrl('admin/addPhoto',array('groupId'=>$model->groupId,'photoId'=>$photo->photoId))?>">编辑</a></td>
			<td style="text-align:center;"><a class="fan1" href="<?=Yii::app()->createUrl('admin/deletePhoto',array('id'=>$photo->photoId))?>">删除</a></td>
        </tr>
<?php        
		}
?>
    </tbody>
</table>
<?php
	}
?>
<?php
}
?>
</div>
